
class Mouse(object):
    '''
    Helps mouse events handling.
    '''

    LEFT = 1
    RIGHT = 2
    MIDDLE = 4
    
    def __init__(self):
        '''
        Constructor
        '''
        self.moved = False
        self.button = None
        self.initial_point = None
        self.actual_point = None
        
    def press(self, event):
        '''
        Must be called when a mouse button is pressed.
        '''
        self.initial_point = self._get_pos(event) 
        self.actual_point = self.initial_point
        self.button = event.button()

    def release(self):
        '''
        Must be called when a mouse button is released.
        '''
        self.moved = False
        self.button = None
        
    def move(self, event):
        '''
        Updates the cursor's position and returns a tuple that shows
        how much the pointer moved.
        '''
        new_point = self._get_pos(event)
        
        result = [(new_point[0] - self.actual_point[0]), 
                  (new_point[1] - self.actual_point[1])]
        
        self.actual_point = new_point
        self.moved = True
        
        return result

    def _get_pos(self, event):
        return event.pos().x(), event.pos().y()